<div id="projects">
 <p>Projects</p>
 <table class="tabular">
  <tr class="header">
   <th>Project</th>
   <th>New</th>
   <th>Open</th>
   <th>Stalled</th>
   <th></th>
  </tr> 
 <% for project in @opened_projects %>
  <tr>
    <td><%= link_to project.name, {:controller => 'project', :action => 'tasks', :id => project.project_id } %></td>
       <% statistics = project.task_statistics %>
    <td><%= statistics[:new] %></td>
    <td><%= statistics[:opened]  %></td>
    <td><%= statistics[:stalled] %></td>
    <td><%= link_to 'New task', {:controller => 'task', :action => 'add', :id => project.project_id} %></td>
  </tr>
 <% end %>
 </table> 
</div>

<div id="highest_priority_tasks">
 <p>10 highest priority tasks that I own</p>
 <table class="tabular">
  <tr class="header">
   <th>#</th>
   <th>Subject</th>
   <th>Priority</th>
   <th>Project</th>
   <th>Status</th>
  </tr> 
 <% for task in @my_hightest_priority_tasks %>
  <tr>
   <td><%= link_to task.task_id, {:controller => 'task', :action => 'show', :id => task.task_id} %></td>
   <td><%= link_to task.subject, {:controller => 'task', :action => 'show', :id => task.task_id} %></td>
   <td><%= task.priority %>/10</td>
   <td><%= link_to task.project.name, {:controller => 'project', :action => 'show', :id => task.project_fk} %></td>
   <td><%= task.status.name %></td>
  </tr> 
 <% end %>
 </table> 
</div>


<div id="refresh">
 <% refresh_rates = [{'noRefresh' => "Don't refresh"}, {60 => 'Every minute'}, {300 => 'Every 5 minutes'}, {600 => 'Every 10 minutes'}, 
                     {900 => 'Every 15 minutes'}, {1800 => 'Every 30 minutes'}, {3600 => 'Every hour'}] %>
 <div class="simple_form">		     
   <form action="/home" method="get">
   <fieldset>
    <div class="form_item">
    <label>Refresh this page</label>
       <select name="RefreshRate">
        <% refresh_rates.each { |element| %>
          <% value = element.keys.first %>
         <option value="<%= value %>"<% if params[:RefreshRate].to_s == value.to_s %>selected="selected"<% end %>><%= element.values.first %></option>
        <% } %>
       </select>
    </div>
    <div class="form_item submit"><input type="submit" value="Set" /></div>   
   </fieldset>
   </form>
 </div>
</div>


<div id="newest_unowned_tasks">
  <p>10 newest unowned tasks</p>
 <table class="tabular">
  <tr class="header">
   <th>#</th>
   <th>Subject</th>
   <th>Project</th>
   <th>Status</th>
   <th>Created</th>
   <th></th>
  </tr> 
 <% for task in @unowned_tasks %>
  <tr>
    <td><%= link_to task.task_id, {:controller => 'task', :action => 'show', :id => task.task_id} %></td>
    <td><%= link_to task.subject, {:controller => 'task', :action => 'show', :id => task.task_id} %></td>
    <td><%= link_to task.project.name, {:controller => 'project', :action => 'show', :id => task.project_fk} %></td>
    <td><%= task.status.name %></td>
    <td><%= task.created.strftime('%F %T') %></td> <!-- use a template helper duration (task.created); -> diference between now and task.created in hours orminutes -->
    <td><% if task.owner == nil %><%= link_to 'Take', {:controller => 'task', :action => 'take', :id => task.task_id} %><% end %></td>
  </tr>
 <% end %>
 </table> 
</div>


